package com.fy.fyspace.common.config;

import lombok.Data;
import okhttp3.OkHttpClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Data
@Configuration
@ConfigurationProperties(prefix = "unsplash")
public class UnsplashConfig {

  /**
   * Unsplash API 访问密钥
   */
  private String accessKey;

  /**
   * API 基础URL
   */
  private String baseUrl;

  /**
   * 连接超时时间（秒）
   */
  private Integer connectTimeout = 10;

  /**
   * 读取超时时间（秒）
   */
  private Integer readTimeout = 30;

  /**
   * 写入超时时间（秒）
   */
  private Integer writeTimeout;

  /**
   * 每页默认数量
   */
  private Integer defaultPerPage;

  /**
   * 最大每页数量
   */
  private Integer maxPerPage;

  @Bean
  public OkHttpClient unsplashHttpClient() {
    return new OkHttpClient.Builder()
        .connectTimeout(connectTimeout, TimeUnit.SECONDS)
        .readTimeout(readTimeout, TimeUnit.SECONDS)
        .writeTimeout(writeTimeout, TimeUnit.SECONDS)
        .build();
  }
}